var app = getApp(), dataApi = require("../../provider/dataApi.js");

require("../../provider/pipe.js");

Page({
    data: {
        title: "",
        statusBarHeight: "",
        titleBarHeight: "",
        list: [],
        params: {},
        isloading: !0,
        pay_open: "",
        freenum: "",
        show: !1,
        item: {},
        total_num: 0
    },
    onLoad: function(options) {
        this.setData({
            statusBarHeight: app.globalData.statusBarHeight,
            titleBarHeight: app.globalData.titleBarHeight,
            title: app.globalData.title
        }), console.log(options), this.getSequence();
    },
    goBack: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    goLx: function(event) {
        var item = event.currentTarget.dataset.item;
        this.setData({
            item: item,
            total_num: item.total_num
        }), app.globalData.id = event.currentTarget.id, 1 == this.data.pay_open && 1 != item.is_can ? this.setData({
            show: !0
        }) : 1 != this.data.pay_open && 1 != item.is_can ? this.setData({
            show: !0
        }) : wx.navigateTo({
            url: "../practice/practice"
        });
    },
    tryAnswer: function() {
        wx.navigateTo({
            url: "../practice/practice"
        });
    },
    cancel: function() {
        this.setData({
            show: !1
        });
    },
    goPay: function() {
        var self = this;
        dataApi.wxPay({
            uid: wx.getStorageSync("uid"),
            id: this.data.item.id,
            type: "1"
        }).then(function(response) {
            console.log(response), wx.requestPayment({
                timeStamp: String(response.data.timeStamp),
                nonceStr: response.data.nonceStr,
                package: response.data.package,
                signType: response.data.signType,
                paySign: response.data.paySign,
                success: function(response) {
                    wx.showToast({
                        icon: "success",
                        title: "支付成功"
                    }), self.setData({
                        show: !1
                    }), self.getSequence();
                },
                fail: function(response) {
                    wx.showToast({
                        icon: "none",
                        title: "支付失败,请重试~"
                    });
                }
            });
        }).catch(function(error) {
            console.log(error);
        });
    },
    getSequence: function() {
        var self = this;
        app.globalData.op = "special", dataApi.sequence({
            uid: wx.getStorageSync("uid"),
            op: "getallspecial"
        }).then(function(response) {
            console.log(response), response.data.list && self.setData({
                list: response.data.list,
                isloading: !1,
                pay_open: response.data.pay_open,
                freenum: response.data.freenum
            });
        }).catch(function(error) {
            console.log(error);
        });
    },
    getErr: function() {
        var self = this, id = this.data.params.id;
        dataApi.myerrList({
            uid: wx.getStorageSync("uid")
        }).then(function(response) {
            var filteredList = [];
            response.data.knowledge_list.map(function(item, index) {
                item.pid == id && filteredList.push(item);
            }), console.log(filteredList), self.setData({
                list: filteredList,
                isloading: !1
            });
        }).catch(function(error) {
            console.log(error);
        });
    },
    onShareAppMessage: function() {}
});